package inge_soft.gestoriusNuevo.business.logic.implementation;


import inge_soft.gestoriusNuevo.business.logic.abstraction.IRandomStringGeneration;

import java.util.Random;

import org.springframework.stereotype.Service;
@Service("generadorPassRandom")
public class RandomStringGeneration implements IRandomStringGeneration{
	private int length;
	private String alphabet = "abcdefghijklmnopqrstuvwxyz123456789";
	private final Random rn = new Random();

	public RandomStringGeneration(){
		this.length = 6;
	}
	public RandomStringGeneration(int length) {
		if (length <= 0)
			throw new IllegalArgumentException(
					"Length cannot be less than or equal to 0");

		this.length = length;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public String getRandomString() {
		StringBuilder sb = new StringBuilder(this.length);

		for (int i = 0; i < this.length; i++) {
			sb.append(alphabet.charAt(rn.nextInt(alphabet.length())));
		}

		return sb.toString();
	}
}
